<?php
add_action( 'restrict_manage_posts', 'cpx_admin_posts_filter_restrict_manage_posts' );
/**
 * First create the dropdown
 * make sure to change store to the name of your custom post type
 */
function cpx_admin_posts_filter_restrict_manage_posts(){
    $type = 'post';
    if (isset($_GET['post_type'])) {
        $type = $_GET['post_type'];
    }

    //only add filter to post type you want
    if ('store' == $type){
        //change this to the list of values you want to show
        //in 'label' => 'value' format
        $values = array(
            'Empty description' => 'filter_empty_store_des',
            'Full description' => 'filter_full_store_des'
        );
        ?>
        <select name="ADMIN_FILTER_FIELD_VALUE">
        <option value=""><?php _e('Filter By Description', 'couponx'); ?></option>
        <?php
            $current_v = isset($_GET['ADMIN_FILTER_FIELD_VALUE'])? $_GET['ADMIN_FILTER_FIELD_VALUE']:'';
            foreach ($values as $label => $value) {
                printf
                    (
                        '<option value="%s"%s>%s</option>',
                        $value,
                        $value == $current_v? ' selected="selected"':'',
                        $label
                    );
                }
        ?>
        </select>
        <?php
    }
}

add_filter( 'parse_query', 'cpx_posts_filter' );
/**
 * if submitted filter by post meta
 * 
 * make sure to change META_KEY to the actual meta key
 * and store to the name of your custom post type
 */
function cpx_posts_filter( $query ){
    global $pagenow;
    $type = 'post';
    if (isset($_GET['post_type'])) {
        $type = $_GET['post_type'];
    }
    if ( 'store' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_FILTER_FIELD_VALUE']) && $_GET['ADMIN_FILTER_FIELD_VALUE'] != '') 
    {
        if($_GET['ADMIN_FILTER_FIELD_VALUE'] == 'filter_empty_store_des')
            add_filter('posts_where','filter_empty');
        if($_GET['ADMIN_FILTER_FIELD_VALUE'] == 'filter_full_store_des')
            add_filter('posts_where','filter_full');
    }
}

function filter_empty($where)
{
    global $wpdb;
    $where .= "
    AND {$wpdb->posts}.post_content = ''
    ";
    return $where;
}
function filter_full($where)
{
    global $wpdb;
    $where .= " AND {$wpdb->posts}.post_content != ''
    ";
    return $where;
}

